package com.rpa.secure.servicerpasecure.filter;
import com.rpa.secure.servicerpasecure.interceptor.RequestWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @className: ChannelFilter
 * @author: lzt
 * @date: 2025/1/24 15:28
 * @Version: 1.0
 * @description:
 */

@Component
@WebFilter(urlPatterns = "/*",filterName = "channelFilter")
@Slf4j
public class ChannelFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("================进入过滤器======================");
        // 防止流读取一次后就没有了, 所以需要将流继续写出去
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        ServletRequest requestWrapper = new RequestWrapper(httpServletRequest);

        filterChain.doFilter(requestWrapper, servletResponse);
    }

}
